/**
 * 最长公共前缀
 * @param {*} strs 
 * @returns 
 */
function longestCommonPrefix(strs = []) {
    if (!strs.length) return "";
    let cur = strs[0];
    for (let i = 1; i < strs.length; i++) {
        let j = 0
        for (; j < cur.length && j < strs[i].length; j++) {
            if (strs[i].charAt(j) !== cur.charAt(j)) {
                break;
            }
        }
        cur = cur.substring(0, j);
        if (!cur) return ""
    }
    return cur;
}

console.log(longestCommonPrefix(["dffkac", "dfkkdfa"]))

function fa(arr = []) {
    if (!arr.length)return "";
    let cur = arr[0];
    // let num = 0;
    for (let i = 1; i < arr.length; i++) {
        let s = 0;
        let min = 0;
        for (let j = 0; j < arr[i].length && s < cur.length; j++) {
            if (cur[s] === arr[i][j]) {
                min++;
            } else {
                cur = cur.substring(0, min);
                break;
            }
            s++;
        }
        if (!cur) return "";
    }
    return cur || "";
}

console.log(fa(["dffkac", "dfkkdfa"]));